<template>
	<view :style="viewColor">
		<view class='bill-details'>
			<view class="navTabBox">
				<view class="longTab">
					<view class="tab-item" v-for="(item,index) in tabList" :key="index" :class="{'on':index == tabIndex-1}" @click="bindTab(index)"><text>{{item.title}}</text></view>
				</view>
			</view>
			<view class='sign-record'>
				<view class='list' v-for="(item,index) in userBillList" :key="index">
					<view class='item'>
						<!-- <view class='data'>{{item.time}}</view> -->
						<view class='listn'>
							<view class='itemn acea-row row-between-wrapper'>
								<view class="icon"><image :src="domain + '/uploads/def/20230727/eaf6db491270fbfb48e60947e9543e0e.png'" mode="widthFix"></view>
								<view>
									<view class='name line1'>{{item.title}}</view>
									<view>{{item.create_time}}</view>
								</view>
								<view class='num' v-if="item.pm ==1">+{{item.number}}</view>
								<view class='num p-color' v-else>-{{item.number}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class='loadingicon acea-row row-center-wrapper' v-if="userBillList.length>0">
					<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
				</view>
				<view v-if="userBillList.length == 0">
					<emptyPage title="暂无账单的记录哦～"></emptyPage>
				</view>
			</view>
		</view>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>
	 
	import {
		getCommissionInfo
	} from '@/api/user.js';
	import {
		mapGetters
	} from "vuex";
	import authorize from '@/components/Authorize';
	import emptyPage from '@/components/emptyPage.vue'
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	export default {
		components: {
			authorize,
			emptyPage
		},
		data() {
			return {
				domain: HTTP_REQUEST_URL,
				loadTitle: '加载更多',
				loading: false,
				loadend: false,
				page: 1,
				limit: 15,
				category: '',
				type: '',
				userBillList: [],
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false ,//是否隐藏授权
				tabList:[
					{
						title:'圈子收益'
					},
					{
						title:'发布需求'
					},
					{
						title:'推广收益'
					}
				],
				tabIndex: 1,
			};
		},
		computed: mapGetters(['isLogin','viewColor']),
		onShow() {
			if (this.isLogin) {
				this.getUserBillList();
			} else {
                this.isAuto = true;
                this.isShowAuth = true
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.category = options.category || '';
			this.tabIndex = options.tab || 1;
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.getUserBillList();
		},
		methods: {
			bindTab(index){
				this.tabIndex = index+1
				this.page =1
				this.loadend = false
				this.loading = false
				this.userBillList = [];
				this.getUserBillList();
			},
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.isShowAuth = false;
				this.getUserBillList();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			/**
			 * 获取账户明细
			 */
			getUserBillList: function() {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = "";
				let data = {
					page: that.page,
					limit: that.limit,
					pm: 1,
				}
				if(that.tabIndex == 1) {
					data.now_money = 3;
				} else if(that.tabIndex == 2) {
					data.now_money = 4;
				} else if(that.tabIndex == 3) {
					data.now_money = 5;
				}
				getCommissionInfo(data).then(function(res) {
					let list = res.data.list,
						loadend = list.length < that.limit;
					that.userBillList = that.$util.SplitArray(list, that.userBillList);
					that.$set(that, 'userBillList', that.userBillList);
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? "哼??~我也是有底线的~" : "加载更多";
					that.page = that.page + 1;
				}, function(res) {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
			},
		}
	}
</script>

<style scoped lang='scss'>
	.navTabBox{
		background: #fff;
		height: 90rpx;
	}
	.longTab{
		display: flex;
		text-align: center;
		padding: 30rpx 0;
	}
	.tab-item{
		width: 50%;
		display: inline-block;
		line-height: 44rpx;
		position: relative;
		text{
			position: relative;
			display: inline-block;
			font-size: 32rpx;
			font-weight: 400;
			color: #1C211D;
		}
	}
	.tab-item.on{
		color: var(--view-theme);
		text{
			font-weight: 500;
		}
		&:before{
			content: "";
			display: inline-block;
			width: 125rpx;
			height: 22rpx;
			background-color: var(--view-theme);
			position: absolute;
			left: 25%;
			bottom: 0;
		}
	}
	.bill-details .nav {
		background-color: #fff;
		height: 90rpx;
		width: 100%;
		line-height: 90rpx;
	}

	.bill-details .nav .item {
		flex: 1;
		text-align: center;
		font-size: 30rpx;
		color: #282828;
	}

	.bill-details .nav .item.on {
		color: var(--view-theme);
		border-bottom: 3rpx solid var(--view-theme);
	}
	.p-color {
		color: var(--view-priceColor)!important;
	}
	.icon {
		width: 60rpx;
		image {
			width:  60rpx;
		}
	}
	.sign-record .list .item .listn {
		background-color: unset;
		.itemn {
			padding: 40rpx 30rpx;
			margin: 30rpx 30rpx 0;
			height: auto;
			border-bottom: 0;
			background-color: #fff;
			.name {
				font-size: 28rpx;
				font-weight: bold;
				color: #323232;
				line-height: 40rpx;
			}
			.num {
				font-size: 34rpx;
				font-weight: bold;
				color: #EA402C;
				line-height: 48rpx;
			}
			.p-color {
			    color: #EA402C!important;
			}
		}
	}
</style>
